From 204a65f737c5d2f6356fcf74e685067a2069c57b Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Fri, 19 Aug 2016 15:23:02 +0300 Subject: [PATCH] babl_fish_reference(), create_name(): add conditional fastpath. Using __thread keyword. Although, it is probably not universally avaliable, so this is just conditional fastpath, if it is detected as unsupported at compile time, the dumb implementation using malloc() is used. --- babl/babl-fish-reference.c | 27 +++++++++++++++++++++++++++ configure.ac | 16 ++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/babl/babl-fish-reference.c b/babl/babl-fish-reference.c index fe75a71..7570e6a 100644 --- a/babl/babl-fish-reference.c +++ b/babl/babl-fish-reference.c @@ -43,6 +43,28 @@ create_name_internal (char *buf, source, destination); } +#ifdef HAVE_TLS + +static __thread char buf[1024]; + +static char * +create_name (const Babl *source, + const Babl *destination, + int is_reference) +{ + int size = 0; + + size = create_name_internal (buf, sizeof(buf), source, destination, is_reference); + + if (size < 0) + return NULL; + + return buf; +} + + +#else + static char * create_name (const Babl *source, const Babl *destination, @@ -72,6 +94,7 @@ create_name (const Babl *source, return buf; } +#endif Babl * babl_fish_reference (const Babl *source, @@ -88,7 +111,9 @@ babl_fish_reference (const Babl *source, /* There is an instance already registered by the required name, * returning the preexistent one instead. */ +#ifndef HAVE_TLS free (name); +#endif return babl; } @@ -117,7 +142,9 @@ babl_fish_reference (const Babl *source, * name, inserting newly created class into database. */ babl_db_insert (babl_fish_db (), babl); +#ifndef HAVE_TLS free (name); +#endif return babl; } diff --git a/configure.ac b/configure.ac index 1bc301b..5bb74fc 100644 --- a/configure.ac +++ b/configure.ac @@ -283,6 +283,22 @@ AM_CONDITIONAL(OS_UNIX, test "$os_win32" != "yes") dnl =========================================================================== +################# +# Check for some not-so-common features +################# + +# babl_fish_reference(), create_name() would like this +AC_MSG_CHECKING([for __thread]) +AC_LINK_IFELSE([AC_LANG_PROGRAM(, [static __thread char buf[1024];])], + [AC_DEFINE(HAVE_TLS, 1, + Define to 1 if compiler supports __thread) + AC_MSG_RESULT([yes])], + [AC_MSG_RESULT([no])]) + + +dnl =========================================================================== + + ######################## # Check for MMX assembly ######################## -- 2.30.2